package com.ttbj.controller.company;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.JsonObject;
import com.ttbj.api.company.CompanyService;
import com.ttbj.api.dto.AccManageData;
import com.ttbj.api.dto.BalanceData;
import com.ttbj.api.dto.CompanyDto;
import com.ttbj.api.dto.Page;
import com.ttbj.api.dto.SalesmanDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.yitong.YTFinancialService;
import com.ttbj.constant.AccTypeEnum;
import com.ttbj.constant.Const;
import com.ttbj.constant.FlagEnum;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.constant.annotation.SystemControllerLog;
import com.ttbj.core.util.RegexUtil;
import com.ttbj.core.util.StringUtil;
import com.ttbj.util.JsonUtil;
import com.ttbj.util.ViewDataUtil;



@Controller
public class CompanyController {
	
	public final static Logger LOGGER = LoggerFactory.getLogger(CompanyController.class);
	
	@Autowired
	private CompanyService companyService;
	@Autowired
	private YTFinancialService ytFinancialService;
	        
	/**
	 * 公司管理页面
	 * @return
	 */
	@RequestMapping(value="/company/company_list.htm")
	public String company_list() {
		return "company/company_list";
	}
	
	/**
	 * 公司编辑页面
	 * @return
	 */
	@RequestMapping(value="/company/edit_company.htm")
	public String edit_company() {
		return "company/edit_company";
	}
	
	/**
	 * 分公司管理页面
	 * @return
	 */
	@RequestMapping(value="/company/branch_company_list.htm")
	public String branch_company_list() {
		return "company/branch_company_list";
	}
	
	/**
	 * 分公司管理页面
	 * @return
	 */
	@RequestMapping(value="/company/branch_company_list2.htm")
	public String branch_company_list2() {
		return "company/branch_company_list2";
	}
	
	/**
	 * 总公司编辑地图
	 * @return
	 */
	@RequestMapping(value="/company/map_company.htm")
	public String map_company(){
		return "/company/map_company";
	}
	
	/**
	 * 编辑分公司
	 * @return
	 */
	@RequestMapping(value="/company/edit_branch_company.htm")
	public String edit_branch_company() {
		return "/company/edit_branch_company";
	}
	
	/**
	 * 公司账户开户
	 * @return
	 */
	@RequestMapping(value="/company/open_acc.htm")
	public String open_acc() {
		return "/company/open_acc";
	}
	
	/**
	 * 公司账户变更
	 * @return
	 */
	@RequestMapping(value="/company/acc_modify.htm")
	public String acc_modify() {
		return "/company/acc_modify";
	}
	
	/**
	 * 公司账户查询
	 * @return
	 */
	@RequestMapping(value="/company/acc_query.htm")
	public String acc_query() {
		return "/company/acc_query";
	}
	
	/**
	 * 余额查询
	 * @return
	 */
	@RequestMapping(value="/company/com_balance.htm")
	public String com_balance() {
		return "/company/com_balance";
	}
	
	/**
	 * 余额查询
	 * @return
	 */
	@RequestMapping(value="/company/balance_info.htm")
	public String balance_info() {
		return "company/balance_info";
	}
	
	/**
	 * 通过公司编号查询公司的编号和名称信息，
	 * 条件是没有被禁用的
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/company/getAllCompanyNumAndName.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCompanyNumAndName(HttpServletRequest request) {
		try {
			SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
			List<CompanyDto> companyDtos = this.companyService.findCompanyNumAndName(salesmanDto);
			return ViewDataUtil.buildSuccessJson("查询公司编号和名称成功", companyDtos);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 查询公司的编号和公司名称
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/company/getCompanyNumAndNameUsedSelect.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCompanyIdAndNameUsedSelect(HttpServletRequest request, HttpServletResponse response) {
		List<CompanyDto> companyDtos = this.companyService.findCompanyNumAndNameUsedSelect();
		return ViewDataUtil.buildSuccessJson("查询公司ID和名称成功", companyDtos);
	}
	
	/**
	 * 分页显示公司列表信息
	 * @param request
	 * @param page 页码
	 * @param companyDto 公司信息
	 * @return 公司列表
	 */
	@RequestMapping(value="/company/getCompanyPage.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCompanyPage(HttpServletRequest request, Page page, CompanyDto companyDto) {
		try {
			List<CompanyDto> companyList = this.companyService.findCompanyPage(page, companyDto);
			int count = 0;
			if (null != companyList) {
				count = this.companyService.findCompanyPageCount(companyDto);
			}
			return ViewDataUtil.buildSuccessPageJson("查询公司信息列表成功", companyList, count);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 增加公司信息
	 * @param request
	 * @param companyDto 公司信息
	 * @return
	 */
	@RequestMapping(value="/company/addToCompanyInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="增加公司信息")
	public String addToCompanyInfo(CompanyDto companyDto) throws Exception {
		try {
			CompanyDto cDto = new CompanyDto();
			cDto = this.companyService.addCompanyInfo(companyDto);
			return ViewDataUtil.buildSuccessJson("增加公司成功", cDto);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 通过ID查询公司信息，用于回显数据
	 * @param request
	 * @param companyId 公司ID
	 * @return 公司信息
	 */
	@RequestMapping(value="/company/getCompanyInfoById.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCompanyInfoById(HttpServletRequest request, @RequestParam Long companyId) {
		CompanyDto cDto = this.companyService.findCompanyById(companyId);
		return ViewDataUtil.buildSuccessJson("查询公司信息成功", cDto);
	}
	
	/**
	 * 修改公司信息
	 * @param request
	 * @param companyDto
	 * @return
	 */
	@RequestMapping(value="/company/modifyCompanyInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="修改公司信息")
	public String modifyCompanyInfo(CompanyDto companyDto) throws Exception{
		try {
			//获取分公司ids
			List<Long> branchCompanyIds = this.companyService.findBranchCompanyIdList(companyDto.getComnumId());
			//修改总公司信息
			this.companyService.editCompanyInfo(companyDto);
			//如果有分公司，则通过分公司id 更新分公司信息
			if (null != branchCompanyIds && branchCompanyIds.size() >0) {
				this.companyService.editBranchCompanyInfo(companyDto, branchCompanyIds);
			}
			return ViewDataUtil.buildSuccessJson("修改公司基本信息成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	
	/**
	 * 修改公司停运状态信息
	 * @param isDelete 停运状态标识，0未停运，1停运
	 * @param companyId 公司id
	 * @param companyNum 公司编号
	 * @return
	 */
	@RequestMapping(value="/company/modifyCompanyDisable.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="修改公司停运状态")
	public String modifyCompanyDisable(@RequestParam Integer isDelete, 
									   @RequestParam Long companyId, 
									   @RequestParam String companyNum) {
		try {
			this.companyService.editCompanyDisable(isDelete, companyId, companyNum);
			return ViewDataUtil.buildSuccessJson("修改公司信息成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	
	/**
	 * 查询总公司下所有的分公司
	 * @param request
	 * @param response
	 * @param companyId
	 * @return
	 */
	@RequestMapping(value="/company/getBranchCompanyInfo.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getBranchCompanyInfo(HttpServletRequest request, Page page, @RequestParam Long companyId) {
		try {
			List<CompanyDto> branchCompanyList = this.companyService.findBranchCompaynInfo(page, companyId);
			int count = 0;
			if (null != branchCompanyList) {
				count = this.companyService.findBranchCompanyInfoCount(companyId);
			}
			return ViewDataUtil.buildSuccessPageJson("查询分公司信息列表成功", branchCompanyList, count);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 查询总公司下所有的分公司
	 * @param request
	 * @param response
	 * @param companyId
	 * @return
	 */
	@RequestMapping(value="/company/getBranchCompanyInfo2.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getBranchCompanyInfo2(HttpServletRequest request, HttpServletResponse response, Page page) {
		try {
			SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
			String comnumNum = salesmanDto.getSalesmanComnum();
			//通过公司编号查询公司的id
			Long companyId = this.companyService.findCompanyIdByNum(comnumNum);
			List<CompanyDto> branchCompanyList = this.companyService.findBranchCompaynInfo(page, companyId);
			int count = 0;
			if (null != branchCompanyList) {
				count = this.companyService.findBranchCompanyInfoCount(companyId);
			}
			return ViewDataUtil.buildSuccessPageJson("查询分公司信息列表成功", branchCompanyList, count);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 新增分公司信息
	 * @param request
	 * @param response
	 * @param companyDto 分公司信息
	 * @return
	 */
	@RequestMapping(value="/company/addToBranchCompanyInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="新增分公司信息")
	public String addToBranchCompanyInfo(CompanyDto companyDto) {
		try {
			this.companyService.addCompanyInfo(companyDto);
			return ViewDataUtil.buildSuccessJson("分公司增加成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	
	@RequestMapping(value="/company/getBranchCompanyIdAndName.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getBranchCompanyIdAndName(HttpServletRequest request, HttpServletResponse response) {
		try {
			SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
			String comnumNum = salesmanDto.getSalesmanComnum();
			List<CompanyDto> companyDtos = this.companyService.findBranchCompanyIdAndName(comnumNum);
			return ViewDataUtil.buildSuccessJson("查询分公司名称", companyDtos);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	
	/**
	 * 通过公司ID只查询公司账户信息 
	 * @param request
	 * @param comnumId 公司ID
	 * @return
	 */
	@RequestMapping(value="/company/getCompanyOpenAccInfo.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCompanyOpenAccInfo(HttpServletRequest request, @RequestParam Long companyId) {
		try {
			CompanyDto cDto = this.companyService.findCompanyOpenAccInfo(companyId);
			return ViewDataUtil.buildSuccessJson("查询公司信息成功", cDto);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 使用易通金服增加账户开户以及账户信息
	 * 注意：页面一定要传 公司id，账户类型，公司编号 
	 * @param request
	 * @param companyDto 账户开户需要用到的信息
	 * @return
	 */
	@RequestMapping(value="/company/addToCompanyOpenAccInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String addToCompanyOpenAccInfo(HttpServletRequest request, CompanyDto companyDto) {
		try {
			this.companyService.addCompanyOpenAcc(companyDto);
			String message = null;
			//获取账户类型
			String accType = companyDto.getComnumType();
			if (AccTypeEnum.TO_PRIVATE.getVal().equals(accType)) {
				message = "对私开户受理成功";
			}else if (AccTypeEnum.TO_PUBLIC.getVal().equals(accType)) {
				message = "对公开户受理成功，等待人工审核";
			}
			return ViewDataUtil.buildSuccessJson(message);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	
	/**
	 * 使用易通金服进行账户变更操作
	 * 注意：页面一定要传 公司id，账户类型，账户号
	 * @param request
	 * @param companyDto 账户开户需要用到的信息
	 * @return
	 */
	@RequestMapping(value="/company/modifyOpenAccInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String modifyOpenAccInfo(HttpServletRequest request, CompanyDto companyDto) {
		try {
			this.companyService.editCompanyAccModify(companyDto);
			String message = null;
			//获取账户类型
			String accType = companyDto.getComnumType();
			if (AccTypeEnum.TO_PRIVATE.getVal().equals(accType)) {
				message = "对私账户变更成功";
			}else if (AccTypeEnum.TO_PUBLIC.getVal().equals(accType)) {
				message = "对公账户变更受理成功，等待人工审核";
			}
			return ViewDataUtil.buildSuccessJson(message);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 使用易通金服进行账户查询
	 * @param request
	 * @param accountNo 账户号
	 * @return 账户的基本信息
	 */
	@RequestMapping(value="/company/accQuery.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String accQuery(HttpServletRequest request, @RequestParam String accountNo) {
		if (StringUtils.isBlank(accountNo)) {
			return ViewDataUtil.buildFailureJson(PlatFormErrorCode.DATA_SECURITY.code(), "没有账户号，不能账户查询");
		}
		AccManageData data =  new AccManageData();
		data.setAccountNo(accountNo);
		try {
			//请求查询接口，返回Map<String, String>
			Map<String, String> map = this.ytFinancialService.getYTFinancialResult(data, 20, "acc_query");
			//如果status为1，则说明正常返回了数据
			if (map.get("status").equals("1")) {
				data = null;
				data = (AccManageData) JsonUtil.jsonToBean(map.get("data"), "data", AccManageData.class);
				return ViewDataUtil.buildSuccessJson("查询账户信息成功", data);
			}else {
				String retInfo = map.get("data").split("\\|")[2];
				return ViewDataUtil.buildFailureJson(1, retInfo);
			}
		} catch (Exception e) {
			return ViewDataUtil.buildFailureJson(1, "查询失败");
		}
	}
	
	/**
	 * 使用易通账户号，调用余额查询接口，查询某一个账户的可用余额，挂账余额，冻结余额
	 * @param accountNo 账户号
	 * @return
	 */
	@RequestMapping(value="/company/getBalanceInfo.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getBalanceInfo(@RequestParam String accountNo) {
		if (StringUtils.isBlank(accountNo)) {
			return ViewDataUtil.buildFailureJson(PlatFormErrorCode.DATA_SECURITY.code(), "没有账户号，不能余额查询");
		}
		try {
			BalanceData balanceData = new BalanceData();
			balanceData.setAccountNo(accountNo);
			//请求余额查询接口，返回Map<String, String>
			Map<String, String> map = this.ytFinancialService.getYTFinancialResult(balanceData, 20, "balance");
			//如果status为1，则说明正常返回了数据
			if (map.get("status").equals("1")) {
				balanceData = null;
				balanceData = (BalanceData) JsonUtil.jsonToBean(map.get("data"), "data", BalanceData.class);
				return ViewDataUtil.buildSuccessJson("余额查询成功", balanceData);
			}else {
				String retInfo = map.get("data").split("\\|")[1];
				return ViewDataUtil.buildFailureJson(1, retInfo);
			}
		} catch (Exception e) {
			return ViewDataUtil.buildFailureJson(1, "调用余额查询接口出现异常");
		}
	}
	
	/**
	 * 每一个公司通过账户号查询自己的可用金额，挂账金额，冻结金额
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/company/balanceQuery.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String balanceQuery(HttpServletRequest request) {
		SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
		String comnumNum = salesmanDto.getSalesmanComnum();
		//获取角色名，只有公司管理员的（admin）的才能显示金额信息
		String roleName = salesmanDto.getRoleDto().getRoleName();
		if (!roleName.equals("admin")) {
			return ViewDataUtil.buildFailureJson(FlagEnum.NO_AUTO.code(), "无此权限！");
		}
		//通过公司编号查询公司账户号
		String comnumAccountNo = this.companyService.findComnumAccountNoByNum(comnumNum);
		//如果公司的账户号为空的话，则直接返回页面提示
		if (null == comnumAccountNo || StringUtils.isBlank(comnumAccountNo)) {
			return ViewDataUtil.buildFailureJson(PlatFormErrorCode.PARAM_IS_NULL.code(), "无法查看，请先开户！");
		}
		try {
			BalanceData balanceData = new BalanceData();
			balanceData.setAccountNo(comnumAccountNo);
			//请求余额查询接口，返回Map<String, String>
			Map<String, String> map = this.ytFinancialService.getYTFinancialResult(balanceData, 20, "balance");
			//如果status为1，则说明正常返回了数据
			if (map.get("status").equals("1")) {
				balanceData = (BalanceData) JsonUtil.jsonToBean(map.get("data"), "data", BalanceData.class);
				return ViewDataUtil.buildSuccessJson("查询成功", balanceData);
			}else {
				String retInfo = map.get("data").split("\\|")[1];
				return ViewDataUtil.buildFailureJson(1, retInfo);
			}
		} catch (Exception e) {
			return ViewDataUtil.buildFailureJson(1, "出现了异常");
		}
	}
	
	
	/**
	 * 查询公司的账户信息（账户号，状态，银行卡号，持卡人等）
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/company/companyAccQuery.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String companyAccQuery(HttpServletRequest request) {
		SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
		String comnumNum = salesmanDto.getSalesmanComnum();
		//获取角色名，只有公司管理员的（admin）的才能显示金额信息
		String roleName = salesmanDto.getRoleDto().getRoleName();
		if (!roleName.equals("admin")) {
			return ViewDataUtil.buildFailureJson(FlagEnum.NO_AUTO.code(), "无此权限！");
		}
		//通过公司编号查询公司账户号
		String comnumAccountNo = this.companyService.findComnumAccountNoByNum(comnumNum);
		//如果公司的账户号为空的话，则直接返回页面提示
		if (null == comnumAccountNo || StringUtils.isBlank(comnumAccountNo)) {
			return ViewDataUtil.buildFailureJson(PlatFormErrorCode.PARAM_IS_NULL.code(), "无法查看，请先开户！");
		}
		try {
			AccManageData accManageData =  new AccManageData();
			accManageData.setAccountNo(comnumAccountNo);
			//请求账户查询接口，返回Map<String, String>
			Map<String, String> map = this.ytFinancialService.getYTFinancialResult(accManageData, 20, "acc_query");
			//如果status为1，则说明正常返回了数据
			if (map.get("status").equals("1")) {
				accManageData = (AccManageData) JsonUtil.jsonToBean(map.get("data"), "data", AccManageData.class);
				accManageData.setCardNo(StringUtil.hideCardNo(accManageData.getCardNo()));	//把银行卡号中间位数设置为*号
				accManageData.setCardName(RegexUtil.nameRegexReplaceAsterisk(accManageData.getCardName()));	//把姓名一个字设置为*号
				return ViewDataUtil.buildSuccessJson("查询成功", accManageData);
			}else {
				String retInfo = map.get("data").split("\\|")[1];
				return ViewDataUtil.buildFailureJson(1, retInfo);
			}
		} catch (Exception e) {
			return ViewDataUtil.buildFailureJson(1, "出现了异常");
		}
	}
	
	/**
	 * (临时接口)使用临时开户按钮对私开户
	 * @param request
	 * @param comnumPhone 开户手机号
	 * @param comnumBankCard 银行卡号
	 * @param comnumBankName 开户银行
	 * @param comnumBankHolder 开户人
	 * @param comnumIdCard 开户身份证号
	 * @param comnumId 企业主键id
	 * @param comnumNum 企业编号
	 * @return
	 */
	@RequestMapping(value="/company/temporaryOpenAcc.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String temporaryOpenAcc(HttpServletRequest request, @RequestParam String comnumPhone,
								   @RequestParam String comnumBankCard, @RequestParam String comnumBankName,
								   @RequestParam String comnumBankHolder, @RequestParam String comnumIdCard,
								   @RequestParam Long comnumId, @RequestParam String comnumNum) {
		try {
			CompanyDto companyDto = new CompanyDto();
			companyDto.setComnumPhone(comnumPhone);
			companyDto.setComnumBankCard(comnumBankCard);
			companyDto.setComnumBankName(comnumBankName);
			companyDto.setComnumBankHolder(comnumBankHolder);
			companyDto.setComnumIdCard(comnumIdCard);
			companyDto.setComnumId(comnumId);
			companyDto.setComnumNum(comnumNum);
			companyDto.setComnumType("00");	//只对私
			//更新企业对私开户信息，并得到账户号
			this.companyService.addCompanyOpenAcc(companyDto);
			return ViewDataUtil.buildSuccessJson(comnumBankHolder + "开户成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 通过公司编号查询提现银行卡号和开户行
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/company/getBankCardAndNameByNum.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getBankCardAndNameByNum(HttpServletRequest request) {
		SalesmanDto salesmanDto = (SalesmanDto) request.getSession().getAttribute(Const.TTBJ_USER_SESSION_KEY);
		String comnumNum = salesmanDto.getSalesmanComnum();
		//获取角色名，只有公司管理员的（admin）的才能显示金额信息
		String roleName = salesmanDto.getRoleDto().getRoleName();
		if (!roleName.equals("admin")) {
			return ViewDataUtil.buildFailureJson(FlagEnum.NO_AUTO.code(), "无此权限！");
		}
		//通过公司编号查询公司账户号
		String comnumAccountNo = this.companyService.findComnumAccountNoByNum(comnumNum);
		//如果公司的账户号为空的话，则直接返回页面提示
		if (null == comnumAccountNo || StringUtils.isBlank(comnumAccountNo)) {
			return ViewDataUtil.buildFailureJson(PlatFormErrorCode.PARAM_IS_NULL.code(), "无法查看，请先开户！");
		}
		try {
			CompanyDto companyDto = this.companyService.findBankCardAndNameByNum(comnumNum);
			String bankCard = StringUtil.hideCardNo(companyDto.getComnumBankCard());	//隐藏银行卡号
			BalanceData balanceData = new BalanceData();
			balanceData.setAccountNo(comnumAccountNo);
			//请求余额查询接口，返回Map<String, String>
			Map<String, String> map = this.ytFinancialService.getYTFinancialResult(balanceData, 20, "balance");
			//如果status为1，则说明正常返回了数据
			if (map.get("status").equals("1")) {
				balanceData = (BalanceData) JsonUtil.jsonToBean(map.get("data"), "data", BalanceData.class);
				JsonObject jsonObject = new JsonObject();
				jsonObject.addProperty("bankName", companyDto.getComnumBankName());
				jsonObject.addProperty("bankCard", bankCard);
				jsonObject.addProperty("accountNo", companyDto.getComnumAccountNo());
				jsonObject.addProperty("balance", balanceData.getBalance());
				return ViewDataUtil.buildSuccessJson("查询成功", jsonObject);
			}else {
				String retInfo = map.get("data").split("\\|")[1];
				return ViewDataUtil.buildFailureJson(1, retInfo);
			}
		} catch (Exception e) {
			return ViewDataUtil.buildFailureJson(1, "出现了异常");
		}
	}
	
}
